var jjychengtoolsbox = {};
// 根据名称获取URL参数
jjychengtoolsbox.GetQueryStringFun = function (name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
};
// 获取Cookie
jjychengtoolsbox.getCookieFun = function (cname) {
  var name = cname + '=';
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i].trim();
    if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
  }
  return null;
};
// 设置Cookie
jjychengtoolsbox.setCookieFun = function (cname, cvalue, exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  var expires = 'expires=' + d.toGMTString();
  document.cookie = cname + '=' + cvalue + '; ' + expires + ';path=/;';
};
// 时间万能转换-兼容IE
jjychengtoolsbox.DateTimeConvertFun = function (time, type) {
  try {
    var d = new Date();
    time = time.toString();
    if (time) {
      if (time.indexOf('T') === -1) {
        try {
          time = time.replace(/-/g, '/');
        } catch (error) { }
      }
      var _time = Number(time);
      if (Number.isNaN(_time) === false) {
        if (time.length === 10) {
          _time = Number(time + '000');
        }
        else if (time.length === 13) {
          _time = Number(time);
        }
        else {
          _time = 0;
        }
        d = new Date(_time);
      }
      else {
        d = new Date(time);
      }
    }
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var day = d.getDate();
    var hours = d.getHours();
    var min = d.getMinutes();
    var seconds = d.getSeconds();
    if (month < 10) month = '0' + month;
    if (day < 10) day = '0' + day;
    if (hours < 0) hours = '0' + hours;
    if (min < 10) min = '0' + min;
    if (seconds < 10) seconds = '0' + seconds;
    var res = '';
    switch (type) {
      case 'yyyy/mm/dd hh:mm':
        res = (year + '-' + month + '-' + day + ' ' + hours + ':' + min);
        break;
      case 'yyyy/mm/dd':
        res = (year + '-' + month + '-' + day);
        break;
      case 'yyyy-mm-dd hh:mm':
        res = (year + '-' + month + '-' + day + ' ' + hours + ':' + min);
        break;
      case 'yyyy-mm-dd':
        res = (year + '-' + month + '-' + day);
        break;
      case 'yyyy年mm月dd日':
        res = (year + '年' + month + '月' + day + '日');
        break;
      default:
        res = (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
        break;
    }
  }
  catch (error) {
    res = '';
  }
  return res;
};
// 截取字符串
jjychengtoolsbox.SliceTxtFun = function (txt, MaxLength) {
  if (txt && txt.length > MaxLength) {
    return txt.slice(0, MaxLength) + '...';
  }
  else {
    return txt;
  }
};

// 过滤全部html
jjychengtoolsbox.FilterHtmlFun = function (txt) {
  if (txt) {
    return txt.replace(/<.*?>/g, '');
  }
  else {
    return txt;
  }
};
// 生成随机数
jjychengtoolsbox.RandomNumberFun = function (min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
// 检查是否手机端访问
jjychengtoolsbox.IsMobileFun = function () {
  if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {
    return true;
  }
  else {
    return false;
  }
}
export default jjychengtoolsbox;
